using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VTPROUTE
    {
        public DataRow Convert2TPROUTE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryTPROUTE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["TPRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["TPRVLO"] = " ".PadRight(2 ); 
         dwReturn["TPRVLB"] = " ".PadRight(2 ); 
         dwReturn["TPRALO"] = " ".PadRight(2 ); 
         dwReturn["TPRALB"] = " ".PadRight(2 ); 
         dwReturn["TPRAENZL"] = " ".PadRight(0 ); 
         dwReturn["TPRAENB"] = " ".PadRight(8 ); 
         dwReturn["TPRAEND"] = " ".PadRight(0 ); 
         dwReturn["TPRNEUB"] = " ".PadRight(8 ); 
         dwReturn["TPRNEUD"] = " ".PadRight(0 ); 
         dwReturn["TPRSTAKZ"] = " ".PadRight(1 ); 
         dwReturn["TPRPROC1"] = " ".PadRight(2 ); 
         dwReturn["TPRLO1"] = " ".PadRight(2 ); 
         dwReturn["TPRLB1"] = " ".PadRight(2 ); 
         dwReturn["TPRLP1"] = " ".PadRight(8 ); 
         dwReturn["TPRART1"] = " ".PadRight(1 ); 
         dwReturn["TPRPRIO1"] = " ".PadRight(0 ); 
         dwReturn["TPRARKZ1"] = " ".PadRight(1 ); 
         dwReturn["TPRKLAS1"] = " ".PadRight(1 ); 
         dwReturn["TPRPROC2"] = " ".PadRight(2 ); 
         dwReturn["TPRLO2"] = " ".PadRight(2 ); 
         dwReturn["TPRLB2"] = " ".PadRight(2 ); 
         dwReturn["TPRLP2"] = " ".PadRight(8 ); 
         dwReturn["TPRART2"] = " ".PadRight(1 ); 
         dwReturn["TPRPRIO2"] = " ".PadRight(0 ); 
         dwReturn["TPRARKZ2"] = " ".PadRight(1 ); 
         dwReturn["TPRKLAS2"] = " ".PadRight(1 ); 
         dwReturn["TPRPROC3"] = " ".PadRight(2 ); 
         dwReturn["TPRLO3"] = " ".PadRight(2 ); 
         dwReturn["TPRLB3"] = " ".PadRight(2 ); 
         dwReturn["TPRLP3"] = " ".PadRight(8 ); 
         dwReturn["TPRART3"] = " ".PadRight(1 ); 
         dwReturn["TPRPRIO3"] = " ".PadRight(0 ); 
         dwReturn["TPRARKZ3"] = " ".PadRight(1 ); 
         dwReturn["TPRKLAS3"] = " ".PadRight(1 ); 
         dwReturn["TPRPROC4"] = " ".PadRight(2 ); 
         dwReturn["TPRLO4"] = " ".PadRight(2 ); 
         dwReturn["TPRLB4"] = " ".PadRight(2 ); 
         dwReturn["TPRLP4"] = " ".PadRight(8 ); 
         dwReturn["TPRART4"] = " ".PadRight(1 ); 
         dwReturn["TPRPRIO4"] = " ".PadRight(0 ); 
         dwReturn["TPRARKZ4"] = " ".PadRight(1 ); 
         dwReturn["TPRKLAS4"] = " ".PadRight(1 ); 
         dwReturn["TPRFILLER"] = " ".PadRight(87 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapTPROUTE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveTPROUTE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryTPROUTE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapTPROUTE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertTPROUTE(dwLocal, ITXDBVERSION);
            }
            UpdateTPROUTE(dwLocal);
        }
        public void InsertTPROUTE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO TPROUTE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryTPROUTE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM TPROUTE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM TPROUTE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "TPROUTE";
            Return = Result;
            return Return;
        }
        public void DeleteTPROUTE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM TPROUTE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateTPROUTE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE TPROUTE SET "
                    +"TPRMANDANT= :TPRMANDANT,"
                    +"TPRVLO= :TPRVLO,"
                    +"TPRVLB= :TPRVLB,"
                    +"TPRALO= :TPRALO,"
                    +"TPRALB= :TPRALB,"
                    +"TPRAENZL= :TPRAENZL,"
                    +"TPRAENB= :TPRAENB,"
                    +"TPRAEND= :TPRAEND,"
                    +"TPRNEUB= :TPRNEUB,"
                    +"TPRNEUD= :TPRNEUD,"
                    +"TPRSTAKZ= :TPRSTAKZ,"
                    +"TPRPROC1= :TPRPROC1,"
                    +"TPRLO1= :TPRLO1,"
                    +"TPRLB1= :TPRLB1,"
                    +"TPRLP1= :TPRLP1,"
                    +"TPRART1= :TPRART1,"
                    +"TPRPRIO1= :TPRPRIO1,"
                    +"TPRARKZ1= :TPRARKZ1,"
                    +"TPRKLAS1= :TPRKLAS1,"
                    +"TPRPROC2= :TPRPROC2,"
                    +"TPRLO2= :TPRLO2,"
                    +"TPRLB2= :TPRLB2,"
                    +"TPRLP2= :TPRLP2,"
                    +"TPRART2= :TPRART2,"
                    +"TPRPRIO2= :TPRPRIO2,"
                    +"TPRARKZ2= :TPRARKZ2,"
                    +"TPRKLAS2= :TPRKLAS2,"
                    +"TPRPROC3= :TPRPROC3,"
                    +"TPRLO3= :TPRLO3,"
                    +"TPRLB3= :TPRLB3,"
                    +"TPRLP3= :TPRLP3,"
                    +"TPRART3= :TPRART3,"
                    +"TPRPRIO3= :TPRPRIO3,"
                    +"TPRARKZ3= :TPRARKZ3,"
                    +"TPRKLAS3= :TPRKLAS3,"
                    +"TPRPROC4= :TPRPROC4,"
                    +"TPRLO4= :TPRLO4,"
                    +"TPRLB4= :TPRLB4,"
                    +"TPRLP4= :TPRLP4,"
                    +"TPRART4= :TPRART4,"
                    +"TPRPRIO4= :TPRPRIO4,"
                    +"TPRARKZ4= :TPRARKZ4,"
                    +"TPRKLAS4= :TPRKLAS4,"
                    +"TPRFILLER= :TPRFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("TPRMANDANT", OracleType.NVarChar).Value = dwData["TPRMANDANT"].ToString(); 
          or1.Parameters.Add("TPRVLO", OracleType.NVarChar).Value = dwData["TPRVLO"].ToString(); 
          or1.Parameters.Add("TPRVLB", OracleType.NVarChar).Value = dwData["TPRVLB"].ToString(); 
          or1.Parameters.Add("TPRALO", OracleType.NVarChar).Value = dwData["TPRALO"].ToString(); 
          or1.Parameters.Add("TPRALB", OracleType.NVarChar).Value = dwData["TPRALB"].ToString(); 
          or1.Parameters.Add("TPRAENZL", OracleType.NVarChar).Value = dwData["TPRAENZL"].ToString(); 
          or1.Parameters.Add("TPRAENB", OracleType.NVarChar).Value = dwData["TPRAENB"].ToString(); 
          or1.Parameters.Add("TPRAEND", OracleType.NVarChar).Value = dwData["TPRAEND"].ToString(); 
          or1.Parameters.Add("TPRNEUB", OracleType.NVarChar).Value = dwData["TPRNEUB"].ToString(); 
          or1.Parameters.Add("TPRNEUD", OracleType.NVarChar).Value = dwData["TPRNEUD"].ToString(); 
          or1.Parameters.Add("TPRSTAKZ", OracleType.NVarChar).Value = dwData["TPRSTAKZ"].ToString(); 
          or1.Parameters.Add("TPRPROC1", OracleType.NVarChar).Value = dwData["TPRPROC1"].ToString(); 
          or1.Parameters.Add("TPRLO1", OracleType.NVarChar).Value = dwData["TPRLO1"].ToString(); 
          or1.Parameters.Add("TPRLB1", OracleType.NVarChar).Value = dwData["TPRLB1"].ToString(); 
          or1.Parameters.Add("TPRLP1", OracleType.NVarChar).Value = dwData["TPRLP1"].ToString(); 
          or1.Parameters.Add("TPRART1", OracleType.NVarChar).Value = dwData["TPRART1"].ToString(); 
          or1.Parameters.Add("TPRPRIO1", OracleType.NVarChar).Value = dwData["TPRPRIO1"].ToString(); 
          or1.Parameters.Add("TPRARKZ1", OracleType.NVarChar).Value = dwData["TPRARKZ1"].ToString(); 
          or1.Parameters.Add("TPRKLAS1", OracleType.NVarChar).Value = dwData["TPRKLAS1"].ToString(); 
          or1.Parameters.Add("TPRPROC2", OracleType.NVarChar).Value = dwData["TPRPROC2"].ToString(); 
          or1.Parameters.Add("TPRLO2", OracleType.NVarChar).Value = dwData["TPRLO2"].ToString(); 
          or1.Parameters.Add("TPRLB2", OracleType.NVarChar).Value = dwData["TPRLB2"].ToString(); 
          or1.Parameters.Add("TPRLP2", OracleType.NVarChar).Value = dwData["TPRLP2"].ToString(); 
          or1.Parameters.Add("TPRART2", OracleType.NVarChar).Value = dwData["TPRART2"].ToString(); 
          or1.Parameters.Add("TPRPRIO2", OracleType.NVarChar).Value = dwData["TPRPRIO2"].ToString(); 
          or1.Parameters.Add("TPRARKZ2", OracleType.NVarChar).Value = dwData["TPRARKZ2"].ToString(); 
          or1.Parameters.Add("TPRKLAS2", OracleType.NVarChar).Value = dwData["TPRKLAS2"].ToString(); 
          or1.Parameters.Add("TPRPROC3", OracleType.NVarChar).Value = dwData["TPRPROC3"].ToString(); 
          or1.Parameters.Add("TPRLO3", OracleType.NVarChar).Value = dwData["TPRLO3"].ToString(); 
          or1.Parameters.Add("TPRLB3", OracleType.NVarChar).Value = dwData["TPRLB3"].ToString(); 
          or1.Parameters.Add("TPRLP3", OracleType.NVarChar).Value = dwData["TPRLP3"].ToString(); 
          or1.Parameters.Add("TPRART3", OracleType.NVarChar).Value = dwData["TPRART3"].ToString(); 
          or1.Parameters.Add("TPRPRIO3", OracleType.NVarChar).Value = dwData["TPRPRIO3"].ToString(); 
          or1.Parameters.Add("TPRARKZ3", OracleType.NVarChar).Value = dwData["TPRARKZ3"].ToString(); 
          or1.Parameters.Add("TPRKLAS3", OracleType.NVarChar).Value = dwData["TPRKLAS3"].ToString(); 
          or1.Parameters.Add("TPRPROC4", OracleType.NVarChar).Value = dwData["TPRPROC4"].ToString(); 
          or1.Parameters.Add("TPRLO4", OracleType.NVarChar).Value = dwData["TPRLO4"].ToString(); 
          or1.Parameters.Add("TPRLB4", OracleType.NVarChar).Value = dwData["TPRLB4"].ToString(); 
          or1.Parameters.Add("TPRLP4", OracleType.NVarChar).Value = dwData["TPRLP4"].ToString(); 
          or1.Parameters.Add("TPRART4", OracleType.NVarChar).Value = dwData["TPRART4"].ToString(); 
          or1.Parameters.Add("TPRPRIO4", OracleType.NVarChar).Value = dwData["TPRPRIO4"].ToString(); 
          or1.Parameters.Add("TPRARKZ4", OracleType.NVarChar).Value = dwData["TPRARKZ4"].ToString(); 
          or1.Parameters.Add("TPRKLAS4", OracleType.NVarChar).Value = dwData["TPRKLAS4"].ToString(); 
          or1.Parameters.Add("TPRFILLER", OracleType.NVarChar).Value = dwData["TPRFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
